package servidorTeste;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import bancoTeste.ConnectionFactory;
import bancoTeste.PreparedstatementFactory;
import clienteTeste.Mensageiro;

public class Gestor extends UnicastRemoteObject implements Mensageiro {

	protected Gestor() throws RemoteException {
		super();
		// TODO Auto-generated constructor stub
	}

	private static final long serialVersionUID = 1L;

	@Override
	public String hello(String nome) throws RemoteException {
		return "Vai trabalhar" + nome;
	}

	@Override
	public void comunica(String comando) throws RemoteException, ClassNotFoundException {
		try{
			String sql ="";
			Connection conn= new ConnectionFactory().getConnection();
				
			sql = comando;
			PreparedStatement pstm = new PreparedstatementFactory().getPreparedStatement(conn, sql);
			
			ResultSet rs = pstm.executeQuery();

						
			while (rs.next()) {
				String usuario = rs.getString("nomeCompleto");
				System.out.println(usuario);
			}
		}
		catch (SQLException sqle)
		{
			   System.err.println("SQLException: "+sqle);
		}
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}

}
